// let x = 10;
// let foo = () => {
// console.log(x);
// let x = 20;
// x++;
// }
// foo()

// let obj = {'1':2}

// function deepClone(obj,  map = new WeakMap()) {
//     if(typeof obj != 'object' || obj == null) {
//         throw new Error('error')
//     }
//     if(map.get(obj)) {
//         return map.get(obj)
//     }
//     let target = Array.isArray(obj) ? [] : {}
//     map.set(obj, target)
//     for(let i in obj) {
//         if(obj.hasOwnProperty(i)) {
//             target[i] = obj[i] instanceof Object ? deepClone(obj[i], map) : obj[i]
//         }
//     }
//     return target
// }

// let obj2 = deepClone(obj)
// console.log(obj2);


// Array.prototype.forEach = function(callback) {
//     for(let i = 0; i < this.length; i++) {
//         callback(this[i], i, arr)
//     }
// }

// let arr = [1,4,5,6]
// arr.forEach((i, item, a) => {
//     console.log(i, item , a)
// })

// console.log(arr.map((i, item) => {
//     return item = 1
// }));
// console.log(arr)

// let arr1 = [1,2,3,4], arr2 = [2,3,5,6,7]

// function mergeSortArr(arr1, arr2) {
//     let res = []
//     let l = 0, r = arr1.length, l1 = 0, r1 = arr2.length
//     while(l < r || l1 < r1) {
//         if(arr1[l] <= arr[l1]) {
//             res.push(arr1[l])
//             l++
//         }
//         else {
//             res.push(arr2[l1])
//             l1++
//         }
//     }
//     if(l > l1) {
//         return res.concat(arr2.slice(l1))
//     }
//     else {
//        return res.concat(arr1.slice(l))
//     }
// }

// console.log(  mergeSortArr(arr1, arr2) );

let data = [{ id: 8, organizationName: 'A', parentId: 7, subData: null },
    , { id: 9, organizationName: 'B', parentId: 7, subData: null }
    , { id: 10, organizationName: 'C', parentId: 7, subData: null }
    , { id: 11, organizationName: 'aa ', parentId: 8, subData: null }
    , { id: 12, organizationName: 'bb', parentId: 9, subData: null }
    , { id: 13, organizationName: 'cc', parentId: 10, subData: null }
    , { id: 7, organizationName: 'string', parentId: 0, subData: null }]



let obj = [{
    name: 'string',
    children: [
        {
            name: 'A',
            children: [{
                name: 'aa'
            }]
        },
        {
            name: 'B',
            children: [
                { name: 'bb' }
            ]
        }, 
        {
            name: 'C',
            children: [{
                name: 'cc'
            }]
        }
    ]
}]
function getData(data, result, pid) {
    for(let item of data) {
        if(item.parentId == pid) {
            const newItem = {name: item.organizationName, children:[]}
            result.push(newItem)
            getData(data, newItem.children, item.parentId)
        }
    }
}

function tree(data, pid) {
    const result = []
    getData(data, result, pid)
    return result
} 

console.log(tree(data, 0));


var menus = [{"backMenu":[{"child":[{"allButtons":["新增","查看","修改","删除","首页总数"],"appFrontIcon":"cuIcon-explore","buttons":["新增","查看","修改","删除","首页总数"],"menu":"用户","menuJump":"列表","tableName":"yonghu"}],"menu":"用户管理"}
                         ,{"child":[{"allButtons":["新增","查看","修改","删除","查看评论","首页总数"],"appFrontIcon":"cuIcon-paint","buttons":["新增","查看","修改","删除","查看评论","首页总数"],"menu":"食堂","menuJump":"列表","tableName":"shitang"},{"allButtons":["新增","查看","修改","删除","查看评论"],"appFrontIcon":"cuIcon-link","buttons":["新增","查看","修改","删除","查看评论"],"menu":"食堂菜品","menuJump":"列表","tableName":"shitangcaipin"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-flashlightopen","buttons":["新增","查看","修改","删除"],"menu":"菜品分类","menuJump":"列表","tableName":"caipinfenlei"}],"menu":"餐饮管理"},
                         {"child":[{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-news","buttons":["新增","查看","修改","删除"],"menu":"店内员工","menuJump":"列表","tableName":"dianneiyuangong"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-link","buttons":["新增","查看","修改","删除"],"menu":"供应商","menuJump":"列表","tableName":"gongyingshang"}],"menu":"人事管理"},
                         {"child":[{"allButtons":["新增","查看","修改","删除","食材库存统计","首页总数","首页统计","进货入库","出库记录","商品预购"],"appFrontIcon":"cuIcon-form","buttons":["新增","查看","修改","删除","食材库存统计","进货入库","出库记录","商品预购","首页总数","首页统计"],"menu":"商品货物","menuJump":"列表","tableName":"shangpinhuowu"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-camera","buttons":["查看","修改","删除"],"menu":"进货入库","menuJump":"列表","tableName":"jinhuoruku"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-medal","buttons":["查看","修改","删除"],"menu":"出库信息","menuJump":"列表","tableName":"chukuxinxi"},{"allButtons":["新增","查看","修改","删除","货物预购统计","首页总数","首页统计"],"appFrontIcon":"cuIcon-attentionfavor","buttons":["查看","修改","删除","货物预购统计","首页统计","首页总数"],"menu":"商品预购","menuJump":"列表","tableName":"shangpinyugou"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-similar","buttons":["新增","查看","修改","删除"],"menu":"货物分类","menuJump":"列表","tableName":"huowufenlei"}],"menu":"商品货物管理"},
                         {"child":[{"allButtons":["查看","修改","回复","删除"],"appFrontIcon":"cuIcon-message","buttons":["查看","修改","回复","删除"],"menu":"意见反馈","tableName":"messages"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-group","buttons":["查看","修改","删除"],"menu":"评论贴吧","tableName":"forum"}],"menu":"综合管理"},
                         {"child":[{"allButtons":["查看","修改"],"appFrontIcon":"cuIcon-camera","buttons":["查看","修改"],"menu":"系统简介","tableName":"systemintro"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-skin","buttons":["查看","修改"],"menu":"轮播图管理","tableName":"config"},{"allButtons":["新增","查看","修改","删除"],"appFrontIcon":"cuIcon-news","buttons":["新增","查看","修改","删除"],"menu":"公告信息","tableName":"news"},{"allButtons":["查看","修改"],"appFrontIcon":"cuIcon-taxi","buttons":["查看","修改"],"menu":"关于我们","tableName":"aboutus"}],"menu":"系统管理"}],"frontMenu":[{"child":[{"allButtons":["新增","查看","修改","删除","查看评论","首页总数"],"appFrontIcon":"cuIcon-goodsnew","buttons":["查看"],"menu":"食堂列表","menuJump":"列表","tableName":"shitang"}],"menu":"食堂模块"},
                         {"child":[{"allButtons":["新增","查看","修改","删除","查看评论"],"appFrontIcon":"cuIcon-medal","buttons":["查看"],"menu":"食堂菜品列表","menuJump":"列表","tableName":"shitangcaipin"}],"menu":"食堂菜品模块"}],"hasBackLogin":"是","hasBackRegister":"否","hasFrontLogin":"否","hasFrontRegister":"否","roleName":"管理员","tableName":"users"},{"backMenu":[],"frontMenu":[{"child":[{"allButtons":["新增","查看","修改","删除","查看评论","首页总数"],"appFrontIcon":"cuIcon-goodsnew","buttons":["查看"],"menu":"食堂列表","menuJump":"列表","tableName":"shitang"}],"menu":"食堂模块"},
                         {"child":[{"allButtons":["新增","查看","修改","删除","查看评论"],"appFrontIcon":"cuIcon-medal","buttons":["查看"],"menu":"食堂菜品列表","menuJump":"列表","tableName":"shitangcaipin"}],"menu":"食堂菜品模块"}],"hasBackLogin":"否","hasBackRegister":"否","hasFrontLogin":"是","hasFrontRegister":"是","roleName":"用户","tableName":"yonghu"}];

var hasMessage = '是';